<template>
    <el-menu
      default-active="2"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b">
      <router-link v-for="(item,index) in menuList" :key="item.key" :to="item.url">
        <el-menu-item :index="''+index+1">
          <i :class="item.icon"></i>
          <span slot="title">{{item.title}}</span>
        </el-menu-item>
      </router-link>

      <el-submenu index="1">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>导航一</span>
        </template>
        <el-menu-item-group>
          <template slot="title">分组一</template>
          <el-menu-item index="1-1">选项1</el-menu-item>
          <el-menu-item index="1-2">选项2</el-menu-item>
        </el-menu-item-group>
        <el-menu-item-group title="分组2">
          <el-menu-item index="1-3">选项3</el-menu-item>
        </el-menu-item-group>
        <el-submenu index="1-4">
          <template slot="title">选项4</template>
          <el-menu-item index="1-4-1">选项1</el-menu-item>
        </el-submenu>
      </el-submenu>
    </el-menu>

  <!--<div class="el-menu">-->
    <!--<router-link v-for="(item,index) in menuList" :key="item.key" :to="item.url">-->
      <!--<li :index="index" ><i :class="item.icon"></i>{{item.title}}</li>-->
    <!--</router-link>-->
  <!--</div>-->

</template>

<script>
  import $ from 'jquery'

  export default {
    name: 'menuList',
    data () {
      return {
        msg: 'menuList',
        menuList:[
          {id:1,title:'首页',url:'/index',icon:'iconfont-zhuye'},
          {id:2,title:'列表',url:'/list',icon:'iconfont-liebiao'},
          {id:3,title:'设置',url:'/setting',icon:'iconfont-shezhi'}
        ]
      }
    },
    methods: {
      handleOpen(key, keyPath) {
        console.log(key, keyPath);
      },
      handleClose(key, keyPath) {
        console.log(key, keyPath);
      },
      init() {
        let timer = window.setInterval(function() {
          var activeMenu = $(".router-link-active li");
          if(activeMenu.length) {
            activeMenu.click();
            window.clearInterval(timer);
          }
        },100);

      }
    },
    mounted: function() {
      this.init();
    },
    updated:function(){

      console.log("updated");
    },
  }
</script>

<style scoped src="@/assets/css/menu.css"></style>
